package com.breadenglish.cms.api.app.gateway.service.impl;

import com.breadenglish.cms.api.app.dao.AudioDao;
import com.breadenglish.cms.api.app.domain.constants.Constants;
import com.breadenglish.cms.api.app.domain.db.Audio;
import com.breadenglish.cms.api.app.domain.query.AudioQuery;
import com.breadenglish.cms.api.app.gateway.model.WhoBeLike;
import com.breadenglish.cms.api.app.gateway.service.WhoBeLikeService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 作者: guo yao
 * 日期: 2016年01月07日
 * 时间: 下午18:24
 */
@Service("whoBeLikeService")
public class WhoBeLikeServiceImpl implements WhoBeLikeService {

    @Resource
    private AudioDao audioDao;

    private static final Logger logger = LoggerFactory.getLogger(WhoBeLikeServiceImpl.class);

    @Override
    public List<WhoBeLike> queryWhoBeLike() throws Throwable {
        List<WhoBeLike> result = new ArrayList<WhoBeLike>();
        // 查询所有未删除并且已发布的数据
        List<AudioQuery> audios = audioDao.queryAudio(new Audio(Constants.VIDEO_STATE_ACTION, Constants.NOT));
        if (CollectionUtils.isNotEmpty(audios)) {
            for (AudioQuery audio : audios) {
                WhoBeLike wbl = WhoBeLike.buildDetails(audio.getAudioId().intValue(), audio.getAudioTitle(), audio.getDetails(), audio.getCreateTime(), audio.getImagePath(), audio.getFilePath(), "fullSizeImage", "nextTitle", "backgoundMusic", "no", true);
                result.add(wbl);
            }
        }
        return result;
    }

    @Override
    public WhoBeLike queryWhoBeLikeById(Long id) throws Throwable {
        AudioQuery audio = audioDao.selectById(id);
        return WhoBeLike.buildDetails(audio.getAudioId().intValue(), audio.getAudioTitle(), audio.getDetails(), audio.getCreateTime(), audio.getImagePath(), audio.getFilePath(), "fullSizeImage", "nextTitle", "backgoundMusic", "no", true);
    }
}
